package org.toycode.solr.extractor.impl;

import java.util.Arrays;
import java.util.List;
import org.apache.solr.common.SolrInputDocument;
import org.toycode.solr.config.Prop;
import org.toycode.solr.extractor.PropertyExtractor;

/**
 * This implementations of the interface {@linkplain PropertyExtractor}
 * provides the content extraction for the type <em>string</em> and
 * <em>strings</em> in config.xml.
 *
 * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
 * @version 1.0.0.1, Aug 26, 2009
 */
final public class StringExtractor implements PropertyExtractor {

    private final List<String> EXTRACTABLE_TYPES = Arrays.asList("string",
                                                                 "strings");

    public void process(final Prop prop, final Object value,
                        final SolrInputDocument solrInputDocument) {
        final String type = prop.type;
        if (type.equals(EXTRACTABLE_TYPES.get(0)) || type.equals(
                EXTRACTABLE_TYPES.get(1))) {
            solrInputDocument.addField(prop.name, value);
        }
    }

    public List<String> getExtractableTypes() {
        return EXTRACTABLE_TYPES;
    }
}
